<?php global $ubi; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>TÙM LUM site</title>
	        
		<link href="include/css/style.css" media="screen" rel="stylesheet" type="text/css" />
		<link href="include/css/styles.css" type="text/css" media="all" rel="stylesheet" id="contact-form-7-css" />
	    <link href="include/css/site.css" media="screen" type="text/css" rel="stylesheet" />
		<link href="include/css/style.pikachoose.css" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery.wysiwyg.css" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery-ui.css" type="text/css" rel="stylesheet" />
		
		<script language="javascript" src="include/script/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery-ui-1.8.14.custom.min.js"></script>
		
		<script language="javascript" type="text/javascript" src="include/script/jquery.pikachoose.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/ajaxupload.3.5.js" ></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/userScript.js"></script>
		
		<script type="text/javascript" language="javascript">
			$.extend({
				minusProvider:function(id, name, url) {
					$.post(url, 
							{id: id}, 
							function(data) {
								if (data != '') {
									alert('Bạn đã trừ điểm quán ' + name, 'Trừ điểm quán');
									$('#plusObj').hide();
									$('#minObj').show();
									$('#lnkPlus').unbind();
									$('#lnkPlus').bind('click', function(event) {
										$.plus(this);
									});
									$('#lnkPlus').html('Cộng điểm');
								} else {
									alert('Có lỗi xảy ra khi trừ điểm quán ' + name + '. Bạn hãy thử lại !!!', 'Trừ điểm quán');
								}
							}
					);
				},
				plusProvider:function(id, name, url) {
					$.post(url, 
							{id: id}, 
							function(data) {
								if (data != '') {
									alert('Bạn đã cộng điểm cho quán ' + name, 'Cộng điểm quán');
									$('#minObj').hide();
									$('#plusObj').show();
									$('#lnkPlus').unbind();
									$('#lnkPlus').bind('click', function(event) {
										$.min(this);
									});
									$('#lnkPlus').html('Trừ điểm');
								} else {
									alert('Có lỗi xảy ra khi bạn công điểm cho quán ' + name + '. Bạn hãy thử lại !!!', 'Cộng điểm quán');
								}
							}
					);
				},
				favouriteProvider:function(id,name,url,ele) {		
					$.post(url, 
							{id: id}, 
							function(data) {
								if (data != '') {
									alert('Bạn đã yêu thích quán ' + name, 'Yêu thích quán');
									$('#favObj').show();
									$(ele).html('Gỡ bỏ yêu thích');
									$(ele).unbind();
									$(ele).bind('click', function() {							
										$.fav(false, this);
									});
									$(ele).attr('title', 'Gỡ bỏ yêu thích');
								} else {
									alert('Có lỗi xảy ra khi yêu thích quán ' + name + '. Bạn hãy thử lại !!!', 'Yêu thích quán');
								}
							}
					);
				},
				removeFavouriteProvider:function(id, name, url, ele) {
					$.post(url, 
							{id: id}, 
							function(data) {
								if (data != '') {
									alert('Bạn đã gỡ bỏ yêu thích quán ' + name, 'Yêu thích quán');
									$('#favObj').hide();
									$(ele).html('yêu thích');
									$(ele).unbind();
									$(ele).bind('click', function() {							
										$.fav(true, this);
									});
									$(ele).attr('title', 'Yêu thích');
								} else {
									alert('Có lỗi xảy ra khi gỡ bỏ yêu thích quán ' + name + '. Bạn hãy thử lại !!!', 'Yêu thích quán');
								}
							}
					);
				},
				fav : function(isFav, ele) {
					var type = 'favourite';
					if (isFav == false) {
						type = 'unfavourite';
					}
					var url = 'index.php?provider&action=' + type;
					var id = <?php echo $providerModel->getProviderID()?>;
					var name = '<?php echo $providerModel->getProvider()?>';

					if (isFav == false) {
						$.removeFavouriteProvider(id, name, url, ele);											
					} else {
						$.favouriteProvider(id, name, url, ele);						
					}
					
					$('#shortinfosocial').load('index.php?provider&action=loadsocialinfo&id=<?php echo $providerModel->getProviderID()?>');
				},
				plus : function(ele) {
					var url = 'index.php?provider&action=plus';
					var id = <?php echo $providerModel->getProviderID()?>;
					var name = '<?php echo $providerModel->getProvider()?>';
					
					$.plusProvider(id, name, url, ele);
					
					$('#shortinfosocial').load('index.php?provider&action=loadsocialinfo&id=<?php echo $providerModel->getProviderID()?>');
				},
				min : function(ele) {
					var url = 'index.php?provider&action=minus';
					var id = <?php echo $providerModel->getProviderID()?>;
					var name = '<?php echo $providerModel->getProvider()?>';
					
					$.minusProvider(id, name, url, ele);

					$('#shortinfosocial').load('index.php?provider&action=loadsocialinfo&id=<?php echo $providerModel->getProviderID()?>');
				}
			});
			
			$(document).ready(function(){
				var isFav = false;
				<?php
					if (!isset($isFav) || !$isFav) {						
				?>		
						isFav = true;
						$('#favObj').hide();						
				<?php
					}
				?>

				var isMin = false;
				<?php					
					if (!isset($isMin) || !$isMin) {
				?>		
						isMin = true;
						$('#minObj').hide();
				<?php
					}
				?>

				<?php
					if (!isset($isPlus) || !$isPlus) { 
				?>		
						$('#plusObj').hide();
				<?php
					}
				?>
				$('#lnkFav').bind('click', {isFav:isFav}, function(event) {
					var isFav = event.data.isFav;
					$.fav(isFav, this);
				});
				if (!isMin) {
					$('#lnkPlus').bind('click', function(event) {
						$.plus(this);	
					}); 
				} else {
					$('#lnkPlus').bind('click', function(event) {
						$.min(this);	
					});
				}
				
				$('#blockSignIn').load('index.php?load&view=blockSignIn&page=viewProvider');
				$('#blockSearch').load('index.php?load&view=blockSearch');
				$('#blockMembers').load('index.php?load&view=blockMembers');
				$('#blockNewestPosts').load('index.php?load&view=blockNewestPosts');
				$('#mainMenu').load('index.php?load&view=menu&location=providers');
				$('.slide').load('index.php?provider&action=loadImage&id=' + '<?php echo $providerModel->getProviderID()?>');
				$('#allComments').load(
						'index.php?comment&action=load&interactType=<?php echo $ubi['PROVIDER']['VALUE'] ?>&indicteeID=<?php echo $providerModel->getProviderID()?>');
				$('#shortinfosocial').load('index.php?provider&action=loadsocialinfo&id=<?php echo $providerModel->getProviderID()?>');		
				$('#shortInfo').load('index.php?provider&action=loadshortinfo&id=<?php echo $providerModel->getProviderID()?>');
				$('#randomItemProvider').load('index.php?load&view=randomItemProvider');

				$('#footer').load('index.php?load&view=footer');

				$('#dlgSendMessage').dialog({autoOpen: false, width:'400px'});
							
				$('#btnGuiComment').click(function() {
					var comment = $('#comment_input').val();
					if (comment != '') {
						var id = <?php echo $providerModel->getProviderID() ?>;
						$.post('index.php?provider&action=comment', {id:id, comment:comment}, function(data) {
							if (data != '0') {
								$('#comment_input').wysiwyg('clear','');
								$('#allComments').load(
									'index.php?comment&action=load&interactType=<?php echo $ubi['PROVIDER']['VALUE'] ?>&indicteeID=<?php echo $providerModel->getProviderID() ?>&page=last');
							} else {
								alert('Có lỗi xảy ra khi gửi comment', 'Xem địa điểm');
							}
						});
					} else {
						alert('Bạn chưa nhập comment !!!');
					}
				});
								
				<?php
					if (isset($_SESSION['userid']) && $_SESSION['userid']) { 
				?>
					$('#comment_input').wysiwyg();	
					var btnUpload=$('#lnkUploadHinh');
					var status=$('#status');
					
					new AjaxUpload(btnUpload, {
						action: 'index.php?provider&action=uploadImage&id=<?php echo $providerModel->getProviderID();?>',
						name: 'imgProvider',
						onSubmit: function(file, ext){
							 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
					            // extension is not allowed 
								status.text('Chỉ tập tin JPG, PNG hoặc GIF được phép upload');
								return false;
							}
							status.text('Đang upload...');
						},
						onComplete: function(file, response){					
							//On completion clear the status
							status.text('');
							//Add uploaded file to list
							if(response == '1'){
								$('.slide').load('index.php?provider&action=loadImage&id=' + '<?php echo $providerModel->getProviderID();?>');
							} else{
								alert('Có lỗi xảy ra. Bạn hãy thử lại', 'Upload hình');
							}
						}
					});
				<?php
				 } 
				?>
			});

			
		</script>
	</head>

	<body>
		<div id="corners">			
			<div class="header" id="main-head">
				<div id="hdr-info">
                	<div style="float:left">
                        <img id="logo" src="include/imgs/logo4.png" alt="The Cook-Off Board" width="235px" />
                        <p id="desc">Tùm Lum, Tả Pí Lù, chia sẻ tất cả ở đây</p>
                    </div>
                    <div class="nav">
                        <div id="mainMenu"></div>
                        <div style="clear:both"></div>
                    </div>
				</div>            
			</div> <!--end header-->
            
			<div class="polaroids">
            	<div class="marginBoxPicCollection" id="randomItemProvider"></div>                                                                            
            </div> <!--end polaris-->
            
            <div id="container">
				<div class="left">
                    <div class="section" id="content">
                        <div class="post clearfix">
                            <div class="post-meta footer">
                                <div style="text-align:center">
                                	<a href="index.php?view&type=user&userid=<?php echo $user->getUserID()?>">                            	
                                        <img src="<?php echo $ubi['SERVER']['RESOURCE_PATH']?>/<?php echo $img?>" class="smallAvatar" />
                                    </a>                                    
                                    <a href="index.php?view&type=user&userid=<?php echo $user->getUserID()?>">
                                        <?php echo $user->getUserName()?>
                                    </a>    
                                </div>
                                <?php
                                	if (isset($_SESSION['userid']) && $_SESSION['userid']) { 
                                ?>
	                                <p class="comment-link-user">
	                                    <a class="a_cursor" title="Gửi Tin Nhắn" onclick="$.sendMessage(<?php echo $user->getUserID()?>)">
	                                        Gửi Tin Nhắn
	                                    </a>
	                                    <br />
	                                    <a class="a_cursor" title="Kết Bạn" onclick="$.makeFriend(<?php echo $user->getUserID()?>)">
			                                 Kết Bạn
	                                    </a>                                
	                                </p>    
                                <?php
                                	} 
								?>
                                <p class="comment-link" id="shortinfosocial"></p>
                                <?php
                                	if (isset($_SESSION['userid']) && $_SESSION['userid']) { 
                                ?>
	                                <p class="comment-link">
	                                	<a class="a_cursor" title="Upload hình" id="lnkUploadHinh">Upload hình</a>
	                                    <br />
	                                    <?php
	                                    	if (!$isFav) { 
	                                    ?>
		                                    <a class="a_cursor" title="Yêu thích" id="lnkFav">Yêu Thích</a>
	                                    <?php
	                                    	} else {
	                                    ?>
	                                    	<a class="a_cursor" title="Gỡ bỏ yêu thích" id="lnkFav">Gỡ bỏ yêu thích</a>
	                                    <?php 		
	                                    	}
	                                    ?>
	                                    <br />
	                                    
	                                    <?php
	                                    	if ($isPlus) { 
	                                    ?>
		                                    	<a class="a_cursor" title="Trừ điểm" id="lnkPlus">Trừ Điểm</a>
	                                    <?php
	                                    	} else {
	                                    ?>
	                                    		<a class="a_cursor" title="Cộng điểm" id="lnkPlus">Cộng Điểm</a>
	                                    <?php 		
	                                    	}
	                                    ?>
	                                    <br />
	                                </p>
	                                  
	                                <div class="comment-link-fav">
	                                	<div id="favObj">
	                                		<img src="include/images/icons/1288740139_heart_48.png" width="24px" title="Bạn đã yêu thích quán này" />
	                                	</div>
	                                	<div id="plusObj">
	                                		<img src="include/images/icons/1288740058_accepted_48.png" width="24px" title="Bạn đã cộng điểm cho quán này" />
	                                	</div>
	                                	<div id="minObj">
	                                		<img src="include/images/icons/circle-minus.png" width="24px" title="Bạn đã trừ điểm cho quán này" />
	                                	</div>	                                	
	                                </div>
                                <?php
                                		if ($providerModel->getUserID() == $_SESSION['userid']) {
                                ?>
	                                	<p class="comment-link">
		                                	<a class="a_cursor" title="Cập nhật" href="index.php?provider&action=edit&id=<?php echo $providerModel->getProviderID()?>">Cập nhật</a>
		                                	<br />
		                                	<a class="a_cursor" title="Chia sẻ hàng hóa" href="index.php?view&type=shareItem&providerId=<?php echo $providerModel->getProviderID()?>">Chia sẻ hàng hóa</a>
		                                </p>
                                <?php
                                		} 		
                                	} 
                                ?>                                                      		
                            </div>                        
                            <div class="right">
                                <div class="header">
                                    <h1><?php echo $providerModel->getProvider()?></h1>                                
                                </div>
                                <div class="slide"></div>
                                <div id="status"></div>
                                <div id="shortInfo"></div>  
                                      
                            </div>
                        </div>
                        <div class="clear" style="clear:both"></div>
                        <div class="post">    
							<div class="section entry">                                	                                        
								<?php
									echo $providerModel->getDescription(); 
								?>                                    
                            </div>
                       	</div>
                       	
                       	<div id="allComments"></div>
                        <?php
                        	if (isset($_SESSION['userid']) && $_SESSION['userid']) { 
                        ?>
	                        <div style="text-align:center">
	                        	<textarea id="comment_input" class="textarea_input" rows="5" cols="72" name="txtProviderCom"></textarea>
	                        	<input type="button" value="Gửi" id="btnGuiComment" />
	                        </div>             
                        <?php
                        	} 
                        ?>
                    </div> 
            	</div>        
                <div class="right">
        			<div class="aside">
                        <ul class="blockRightSide">	
                        	<li class="blockRight" id="blockMap">
                        		<img src="<?php echo $imgUrl?>" />
                        	</li>
                        	<h2 class="widgettitle">Đăng nhập</h2>
                            <li class="blockRight" id="blockSignIn"></li>
                            
                            <h2 class="widgettitle">Tìm kiếm</h2>
                            <li class="blockRight" id="blockSearch"></li>
                            
                            <h2 class="widgettitle">Thành viên</h2>                                            
                            <li class="blockRight" id="blockMembers"></li>
                            
                            <h2 class="widgettitle">Bài đăng mới nhất</h2>
                            <li class="blockRight" id="blockNewestPosts"></li>                          
                        </ul>
                    </div>        
                </div>
			</div>		
            
            <div id="footer" class="footer clearfix"></div>       
		</div>
		
		<div id="dlgSendMessage" title="Gửi tin nhắn">
			<form id="frmSendMess" name="frmSendMess">
				Tiêu đề<br />
				<input type="hidden" name="receiver" />
				<input type="text" name="title" size="44" /><br />
				Nội dung<br />		
				<textarea rows="4" cols="42" name="mess"></textarea>
				<br /><br />
				<input type="submit" value="Gửi" />
			</form>
		</div>
	</body>
</html>